package com.thread.sync.sync03;

public class MYThreadLocal {
    private ThreadLocal<String> threadLocal = new ThreadLocal<String>();

    public void setTh(String str) {
        this.threadLocal.set(str);
    }

    public String getTh() {
        return this.threadLocal.get();
    }

    public static void main(String[] args) {
        MYThreadLocal myThreadLocal = new MYThreadLocal();
        Thread t1 = new Thread(() -> {
            myThreadLocal.setTh("侯征");
            String th = myThreadLocal.getTh();
            System.out.println("获取到的local:" + th);
        }, "t1");
        Thread t2 = new Thread(() -> {
            String th = myThreadLocal.getTh();
            System.out.println("获取到的local:" + th);
        }, "t2");
        t1.start();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t2.start();
    }
}
